package com.io.test;

import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;

public class test {
    public static void main(String[] args) throws IOException {
////        int a = System.in.read();
//        System.out.println("fdsafdas");
        try{
            System.setProperty("file.encoding","UTF-16");
            System.out.println(System.getProperty("file.encoding"));
            String s = "不";
            char c = s.charAt(0);
            System.out.println("char:"+c);
            System.out.println("10101010:"+Integer.toBinaryString(c));
            InputStream i = new FileInputStream("/usr/local/git/knowledge/IO_NIO/src/main/java/com/io/test/test");

            System.out.println("fileinputstream:"+Integer.toBinaryString(i.read())+Integer.toBinaryString(i.read())+Integer.toBinaryString(i.read()));

            RandomAccessFile randomAccessFile = new RandomAccessFile("/usr/local/git/knowledge/IO_NIO/src/main/java/com/io/test/test","rw");
            RandomAccessFile randomAccessFile2 = new RandomAccessFile("/usr/local/git/knowledge/IO_NIO/src/main/java/com/io/test/test1","rw");
            FileChannel fileChannel1 = randomAccessFile.getChannel();
            FileChannel fileChannel2 = randomAccessFile2.getChannel();
//            ByteBuffer buffer =ByteBuffer.allocate(1024);
//            fileChannel1.read(buffer);
//            buffer.flip();
//            fileChannel2.write(buffer);

            fileChannel1.transferTo(0,fileChannel1.size(),fileChannel2);




       }catch (Exception e){
            System.err.print(e);
        }
    }
}
